//https://leetcode.cn/problems/n-th-tribonacci-number/description/
//第 n 个泰波那契数
//泰波那契序列 Tn 定义如下： 
//T0 = 0, T1 = 1, T2 = 1, 且在 n >= 0 的条件下 Tn+3 = Tn + Tn+1 + Tn+2
//给你整数 n，请返回第 n 个泰波那契数 Tn 的值。

class Solution {
public:
    int tribonacci(int n) {
        int a[3] = {0, 1, 1};
        for(; n > 2; n--)
        {
            int t = a[0] + a[1] + a[2];
            a[0] = a[1]; a[1] = a[2]; a[2] = t;
        }
        return a[n];
    }
};